<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;





//前台列表控制器
class ListController extends Controller{

	//构造函数
	public function __init()
	{
		
		
	}
	
    //列表页面
    public function index(){
//  	var_dump($_GET);die;
//		获得该条数据然后分配到前台
		$cid = Q('get.cid',0,'intval');
//		var_dump($cid);die;
		$goodsModel = new \Common\Model\Goods;
		$cateModel = new \Common\Model\Cate;
//			获取头部数据
//			获取当前分类所有的子集
//			作为getSon 的一个子集
			$cateData = $cateModel -> get();
			$cids = $cateModel -> getson($cateData,$cid);
//			var_dump($cids);die;
//			将当前类cid压入
			$cids[] = $cid;
//			var_dump($cids);die;
//			转成字符串
			$cids = implode(",", $cids);
//			查询在这些cid中的商品，然后分配
			$goodsData = $goodsModel
				-> join('snshop_categroy','snshop_categroy_cid','=','cid')
				-> join('snshop_detail','gid','=','snshop_goods_gid')
				-> where('snshop_categroy_cid IN ('.$cids.')')
				-> get();
			
//			分配前台
//			大小图路径
			$dirN = "Upload/Content/16/07/pro-z/";
			foreach($goodsData as $k => $v){
				$goodsData[$k]['small'] = explode(";", $v['small']);
				$small = $goodsData[$k]['small'];
				foreach($small as $kk => $vv){
					$goodsData[$k]['small'][$kk] = $dirN.$vv;
				}
			}
			View::with('dirN',$dirN);
//			var_dump($goodsData);die;
			View::with('goodsData',$goodsData);

//				LS-------
//			获取cid
			$cid = Q('get.cid',0,'intval');
//			p($cid);die;
//			通过cid查询他的子类，再将当前的cid压入
			$cidCate = Db::table('snshop_categroy')
						-> where('cid',$cid)
						-> first();
//			p($cidCate);die;
//			传入模型中处理数据
			$cids = $cateModel -> getson($cateData,$cid);
//			压入当前cid
			$cids[] = $cid;
//			p($cids);die;
//			通过cids查询所有属于该cids的商品id
			$goodsCids = Db::table('snshop_goods')
						-> where("snshop_categroy_cid IN (".implode(',', $cids).")")
						->lists('gid');
//			p($goodsCids);die;
			
//			通过商品id查询他所对应的商品属性
			$GoodsAttrArr = Db::table('snshop_goods_attr')
							-> where("snshop_goods_gid IN (".implode(',', $goodsCids).")")
							-> groupBy('gtvalue')
							-> get();
//			p($GoodsAttrArr);die;
			
//			然后重组数组，获取gtvalue所属的类型
			$listTypeData = array();
			
			foreach($GoodsAttrArr as $k => $v){
				$listTypeData[$v['taid']][] = $v;
				
			}
			
//			p($listTypeData);die;
			
			


//				LS-------
				



		View::make();
    }
}
